package com.imooc.hadoop.mapreduce.hive;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @program: hadoop
 * @description: TaskEtlMapper
 * @author: zengchen
 * @create: 2021-04-21 09:14
 **/
public class TaskEtlMapper extends Mapper<LongWritable, Text, NullWritable, Text> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        if(value != null && StringUtils.isNotBlank(value.toString())){
            context.write(NullWritable.get(),new Text(
                    value.toString().replaceAll("},[{]","|")
                    .replaceAll("sub:","")
                    .replaceAll("score:","")
                    .replaceAll("[{]","")
                    .replaceAll("}",""))
            );
        }
    }

}
